//
//  FWCHomeLoginView.swift
//  微博项目001
//
//  Created by 樊武超 on 16/4/6.
//  Copyright © 2016年 樊武超. All rights reserved.
//

import UIKit
import SnapKit

//声明协议，点击登录或者注册按钮的方法监听
@objc protocol FWCHomeLoginViewDelegate:NSObjectProtocol{

    optional func dengLuBtnDidClick()
    optional func zhuceBtnDidClick()
    
  }


class FWCHomeLoginView: UIView {
   weak var LoginViewDelegate: FWCHomeLoginViewDelegate?
    
    override init(frame: CGRect) {
        super.init(frame: frame)

    
        loadSubView()
      
    }
    func setView(imageName: String,title: String,isAnimation: Bool=false ){
        if isAnimation != false {
        
        animation()
            
        }else{
            iconImageView.image=UIImage(named: imageName)
            textLable.text=title
            scroleImageView.hidden=true
            beijingImage.hidden=true
        
        }
        
    
    
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func loadSubView(){
    
        addScroleImage()
        
        addBeiJingImageView()
    
        addIconImage()
        
        addButn()
        let num: CGFloat=237/255.0
        backgroundColor=UIColor(red: num, green: num, blue: num, alpha: 1)
        
        
    }
    
    func addBeiJingImageView(){
    addSubview(beijingImage)
        beijingImage.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(scroleImageView.snp_center)
        }
    
    
    }
    
    func addScroleImage(){
        addSubview(scroleImageView)
        
        scroleImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.center.x)
            make.centerY.equalTo(self.center.y-80)
        }

    
    }
    private func animation(){
        
        let animation=CABasicAnimation()
        
        animation.keyPath="transform.rotation.z"
        
        animation.fromValue=NSNumber(double: 0.0)
        
        animation.toValue=NSNumber(double: M_PI*2.0)
        
        animation.duration=10
        animation.repeatCount=MAXFLOAT
        animation.removedOnCompletion=false
        
       scroleImageView.layer.addAnimation(animation,forKey: nil)
        
        
    }

    func addIconImage(){
       addSubview(iconImageView)
        iconImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.center.x)
            make.centerY.equalTo(self.center.y-80)
        }
    
        addSubview(textLable)
        textLable.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(self.center.x)
            make.centerY.equalTo(self.center.y-80+scroleImageView.bounds.size.height*0.5+16.0)
            make.width.equalTo(230)
            make.height.equalTo(40)
           }

    }
    
    func addButn(){
        addSubview(loginBtn)
        addSubview(zhuceButn)
        loginBtn.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(textLable.snp_left)
            make.top.equalTo(textLable.snp_bottom).offset(16)
            make.width.equalTo(100)
            
         }
        zhuceButn.snp_makeConstraints { (make) -> Void in
            
            make.right.equalTo(textLable.snp_right)
            make.top.equalTo(textLable.snp_bottom).offset(16)
            make.width.equalTo(100)
            
        }

    }
    
    lazy var scroleImageView:UIImageView={
    let imageview=UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    
        imageview.sizeToFit()
    return imageview
    }()
    lazy var iconImageView:UIImageView={
    let imageView=UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
        
        imageView.sizeToFit()
        return imageView
    
    }()
    
    lazy var textLable:UILabel={
    let lable=UILabel()
        lable.text="关注一些人,回到这里看看有什么惊喜"
        lable.textAlignment = .Center
        lable.textColor=UIColor.darkGrayColor()
        lable.numberOfLines=0
        lable.font = UIFont.systemFontOfSize(14)
        lable.sizeToFit()
        return lable
    
    }()
    
    lazy var loginBtn:UIButton={
    let butn=UIButton()
        butn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState:UIControlState.Normal)
        butn.setTitle("登录", forState: .Normal)
       butn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        butn.addTarget(self, action: "dianjidenglu", forControlEvents: .TouchUpInside)
        return butn
    }()
    func dianjidenglu(){
//    print("点击了登录按钮")
     LoginViewDelegate?.dengLuBtnDidClick!()
    }
    lazy var zhuceButn:UIButton={
        
    let butn=UIButton()
        butn.setBackgroundImage(UIImage(named: "common_button_white_disable"), forState:UIControlState.Normal)
        
        butn.setTitle("注册", forState: .Normal)
        butn.setTitleColor(UIColor.orangeColor(), forState: .Normal)
        butn.addTarget(self, action: "dianjilezhuce", forControlEvents: .TouchUpInside)
        return butn
    }()
    func dianjilezhuce(){
    
    LoginViewDelegate?.zhuceBtnDidClick!()
    }
    
    lazy var beijingImage: UIImageView={
    let imageView=UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
        
    
    return imageView
    }()
    
}
